import pygame
import setting
class person:
    def __init__(self,ai_settings,screen):
        self.screen=screen
        self.ai_settings=ai_settings
        self.image=pygame.image.load('picture/charter.bmp')  # 放图片
        self.image=pygame.transform.scale(self.image,(60,100))
        self.health=10
        self.g=2 #重力加速度
        self.vectory_y=float(0)
        self.frame=0
        self.collide_delta=0
        self.jump_delta=6
        self.rect=self.image.get_rect()   # 获取图片的外接矩形
        self.screen_rect=screen.get_rect()
        self.rect.centerx=self.screen_rect.centerx
        self.movex=float(self.rect.centerx)         # movex为人物在水平面上的坐标
        self.rect.centery=self.screen_rect.centery  # movey为人物在竖直面上的坐标
        self.movey=float(self.rect.centery)
        self.rect.bottom=self.screen_rect.bottom
        self.move_right=False
        self.move_left=False
    def gravity(self):    #模拟引力
        if self.rect.centery <900:
            self.vectory_y+=self.g
            self.movey+=self.vectory_y
    def update(self):
        if self.move_right:
            self.movex+=self.ai_settings.charter_speed_factory
        elif self.move_left:
            self.movex-=self.ai_settings.charter_speed_factory
        self.rect.centerx=self.movex
        self.rect.centery=self.movey+self.vectory_y
    def blitime(self):
        self.screen.blit(self.image,self.rect)